package com.zhan.rkforum.event;

import com.alibaba.fastjson.JSONObject;
import com.zhan.rkforum.bean.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class EventProducer {

    private static final Logger logger = LoggerFactory.getLogger(EventProducer.class);

    @Autowired
    private  KafkaTemplate<String, Object> kafkaTemplate;


    public void fireEvent(Event event){
        logger.info("生产者{}生产的消息为：{}", event.getUserId(),event.toString());
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
    }



}
